<?
include("includes/functions.php");

if (!empty($_POST[siteArea])) { $siteArea = $_POST[siteArea]; }
else { $siteArea = $_GET[siteArea]; }

if ($siteArea == "Amazon") {
	$pageTitle = "Edit Amazon Product Categories";
}

// Add new category
if ($_GET[newCat] == 1) {
	$sql = "INSERT into ss_mainCat (
			Category,
			SiteArea,
			Visible
			) values (
			'$newCat',
			'$siteArea',
			'1'
			)";
	$result = mysql_db_query($dbname,$sql);
}
// Edit category
if (!empty($_GET[editCat])) {
	$category = fieldToDB($_POST[category]);
	$catID    = $_GET[editCat];
	$sql = "UPDATE ss_mainCat SET Category = '$category' WHERE ID = '$catID'";
	$result = mysql_db_query($dbname,$sql);
}

// Get all categories for this siteArea
$sql = "SELECT * from ss_mainCat WHERE SiteArea = 'Amazon' ORDER BY Category";
$result = mysql_db_query($dbname,$sql); 

include("includes/popup_header.php");
?>
<table border="0" style="border: 1px solid #c0c0c0" width="100%">
<tr>
	<td bgcolor="#ffffcc"><form action="<?=$_SERVER[PHP_SELF]; ?>?newCat=1" name="newCatForm" method="POST">
		<input type="hidden" name="siteArea" value="<?=$siteArea; ?>">
		<input type="text" size="30" name="newCat" value="New Category" onFocus="document.newCatForm.newCat.value='';">
	</td>
	<td bgcolor="#ffffcc" align="center"><input type="image" src="images/button_add.gif" border="0" title="Add Category"></form></td>
</tr>

<?
$i=0;
while ($value = mysql_fetch_assoc($result)) {
	$catID    = $value[ID];
	$category = stripslashes($value[Category]);
	
	if (($i % 2) > 0) { $class = "altrow"; $bgcolor = "#eeeeee"; }
	else { $class = null; $bgcolor = "#ffffff"; }
	
	echo "<tr>\n";
	echo "<td width=\"70%\" bgcolor=\"$bgcolor\">\n";
	echo "<form action=\"$_SERVER[PHP_SELF]?editCat=$catID\" method=\"POST\">\n";
	echo "<input type=\"text\" name=\"category\" value=\"$category\" size=\"30\">\n";
	echo "</td>\n";
	echo "<td align=\"center\" bgcolor=\"$bgcolor\">\n";
	echo "<input type=\"image\" src=\"images/button_edit.gif\" border=\"0\" title=\"Edit Category\">\n";
	echo "<a href=\"$_SERVER[PHP_SELF]?delete=1&catID=$catID\" title=\"Delete Category\" onClick=\"return confirmSubmit('Are you sure you want to delete this Category?');\">\n";
	echo "<img src=\"images/button_delete.gif\" border=\"0\" title=\"Delete this Category\"></a></form>\n";
	echo "</td>\n";
	echo "</tr>\n";
	$i++;
}
?>
</table>
<? include("includes/popup_footer.php");